﻿#region using
using System;
using System.Threading.Tasks;
using Linq2Crm.ObjectModel.DomainObject;
using SilverCrmSoap.CrmSdk;


#endregion

namespace Linq2Crm.Request.SpecificRequest
{
	public sealed class GetViewRequest : RequestBase
	{
		private GetViewRequest(Type type) : base(type)
		{
		}

		internal QueryExpression Expression { get; set; }

		public bool UseUserQuery { get; set; }

		#region Overrides of RequestBase
		internal override void Execute()
		{
			throw new NotImplementedException("Use ExecuteAsync instead");
		}

		internal override async Task<ResponseBase> ExecuteAsync()
		{
			return await DomainObjectContext.Instance.ExecuteGetViewRequest(this);
		}
		#endregion

		public static GetViewRequest CreateFor<T>(bool takeUserView = false)
			where T : IDomainObject
		{
			return new GetViewRequest(typeof (T))
				{
					UseUserQuery = takeUserView
				};
		}
	}
}